//
//  ZJProtocolViewController.swift
//  mini
//
//  Created by Mac on 2017/5/22.
//  Copyright © 2017年 Mac. All rights reserved.
//

import UIKit
import WebKit
import SnapKit
class ZJProtocolViewController: UIViewController {
    
    var webView:WKWebView?
    var url:String?
    
    override func loadView() {
        
        super.loadView()
        
        webView = WKWebView()
        
        webView?.navigationDelegate = self
        
        webView?.uiDelegate = self
        
        let request  = URLRequest(url: URL(string:url!)!)
        
        webView?.load(request)
        
        webView?.backgroundColor = .white
        
        view.addSubview(webView!)
    }

    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        setNav()
        

        // Do any additional setup after loading the view.
    }

    func  setNav()  {
        
        view.backgroundColor = .white
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named:"YC_Nav_Back"), style: .plain, target: self, action: #selector(self.back))
        
        webView?.snp.makeConstraints({ (make) in
            make.edges.equalTo(view)
        })
        
    }
    
    func back()  {
        
       navigationController?.popViewController(animated: true)
        
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    



}


extension ZJProtocolViewController : WKNavigationDelegate,WKUIDelegate{
    
    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
        title = "正在加载中。。。"
    }
    
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        title = webView.title
        YCHud.dismiss()
    }
    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
        title = "网络状况不佳！"
        YCHud.showError(withStatus: "网络状况不佳！")
    }
}
